<template>
  <div class="container">
    <div class="app-container">
      <div class="search">
        <el-form class="search-form">
          <el-form-item label="订单编号：" label-width="120px">
            <el-input
              v-model="pageParams.orderNo"
              placeholder="请输入"
              style="width: 200px"
            ></el-input>
          </el-form-item>
          <el-form-item label="选择日期：" label-width="120px">
            <el-date-picker
              v-model="date"
              style="width:350px"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button
              class="search-btn"
              size="mini"
              type="primary"
              icon="el-icon-search"
              @click="searchOrder"
              >查询</el-button
            >
          </el-form-item>
        </el-form>
      </div>
      <div class="list">
        <el-table :data="tableData" style="width: 100%">
          <el-table-column width="80px" label="序号">
            <template v-slot="{ row }"> {{ row.index }} </template>
          </el-table-column>
          <el-table-column prop="orderNo" label="订单编号"> </el-table-column>
          <el-table-column prop="skuName" label="商品名称"> </el-table-column>
          <el-table-column label="订单金额（元）">
            <template v-slot="{row}">{{row.price / 100}}</template>
          </el-table-column>
          <el-table-column prop="innerCode" label="设备编号"> </el-table-column>
          <el-table-column label="订单状态">
            <template v-slot="{row}">{{row.payStatus === 1 ? '出货成功' : '出货失败'}}</template>
             </el-table-column>
          <el-table-column label="订单日期">
            <template v-slot="{row}">{{row.updateTime.split('T').join(' ')}}</template>
             </el-table-column>
          <el-table-column label="操作">
            <template v-slot="{ row }">
              <el-button type="text" @click="checkInfo(row)"
                >查看详情</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <el-row type="flex" justify="space-between" style="margin-top: 20px">
          <span class="pageCount"
            >共{{ pageParams.totalCount }}条记录 第{{ pageParams.pageIndex }}/{{
              pageParams.totalPage
            }}页</span
          >
          <el-pagination
            layout="slot"
            :current-page.sync="pageParams.pageIndex"
            :page-size="pageParams.pagesize"
            :total="pageParams.totalPage"
          >
            <el-button
              type="primary"
              :disabled="pageParams.pageIndex === 1 ? true : false"
              class="pagi-btn"
              :class="{ disabled: pageParams.pageIndex === 1 }"
              @click="goPrev"
              >上一页</el-button
            >
            <el-button
              type="primary"
              :disabled="
                pageParams.pageIndex === pageParams.totalPage ? true : false
              "
              :class="{
                disabled: pageParams.pageIndex === pageParams.totalPage,
              }"
              class="pagi-btn"
              @click="goNext"
              >下一页</el-button
            >
          </el-pagination>
        </el-row>
      </div>
      <!-- 查看详情 -->
      <order-info v-if="showInfoDialog"  :isShow.sync="showInfoDialog" :orderInfo="orderInfo" />
    </div>
  </div>
</template>
<script>
import {
  searchOrderApi
} from "@/api/order";
import orderInfo from '@/views/order/components/orderInfo.vue'
import moment from 'moment';
export default {
  components:{
    orderInfo
  },
  data() {
    return {
      tableData: [],
      title: "",
      date:[],
      orderInfo:{},
      showInfoDialog: false,
      pageParams: {
        pageIndex: 1,
        pageSize: 10,
        orderNo:'',
        startDate:'',
        endDate:'',
      },
    };
  },
  created() {
    this.searchOrder();
  },
  methods: {
    // 搜索
    async searchOrder() {
      const res = await searchOrderApi({
        ...this.pageParams,
      });
      this.tableData = [...res.currentPageRecords];
      this.pageParams.pageIndex = +res.pageIndex;
      this.pageParams.pageSize = +res.pageSize;
      this.pageParams.totalPage = +res.totalPage;
      this.pageParams.totalCount = +res.totalCount;

      // 序号
      let pageNow = this.pageParams.pageIndex;
      this.tableData.forEach((item, index) => {
        this.$set(
          item,
          "index",
          pageNow > 1 ? (pageNow - 1) * 10 + index + 1 : index + 1
        );
      });
    },

    async checkInfo(row){
      console.log(row);
      this.orderInfo = row
      this.showInfoDialog = true
    },
   
    // 上一页
    goPrev() {
      this.pageParams.pageIndex--;
      this.searchOrder();
    },
    // 下一页
    goNext() {
      this.pageParams.pageIndex++;
      this.searchOrder();
    },
  },
  watch:{
    date(newVal){
      const momentobj0 = moment(newVal[0])
      const formatted0 = momentobj0.format('YYYY-MM-DD')
      const momentobj1 = moment(newVal[1])
      const formatted1 = momentobj1.format('YYYY-MM-DD')
      this.pageParams.startDate = formatted0
      this.pageParams.endDate = formatted1
    }
  }
};
</script>

<style lang="scss" scoped>
.app-container {
  background-color: #f8fafd;
  padding: 20px;
  .search {
    background-color: #fff;
    display: flex;
    height: 64px;
    align-items: center;
    padding-top: 23px;
    margin-bottom: 20px;
    .search-form {
      display: flex;
      align-items: center;
      .search-btn {
        background-color: #5f84ff;
        border: none;
        margin-left: 15px;
        font-size: 16px;
        height: 36px;
        width: 80px;
        text-align: center;
        padding: 0;
      }
    }
  }
  .list {
    padding: 20px;
    background-color: #fff;

    .btns {
      margin-bottom: 15px;
    }
    .add-btn {
      width: 80px;
      text-align: center;
      padding: 12px 0px;
      background-color: #ff8035;
      border: none;
      font-size: 14px;
    }
    .setting-btn {
      border: none;
      background-color: #fbf4f0;
      color: #716762;
      width: 80px;
      text-align: center;
      padding: 12px 0px;
    }
    .pageCount {
      color: #dbdfe5;
      margin-left: 10px;
    }
  }
  .pagi-btn {
    background-color: #d5ddf8;
    color: #606266;
    width: 70px;
    height: 32px;
    text-align: center;
  }
  .disabled {
    background-color: #eceff8;
    color: #d2d7dd;
  }
  .del {
    color: #ff5a5a;
  }
}
.vmImage{
  width: 24px;
  height: 24px;
  border-radius: 12px;
}
</style>
